﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AcademyPopcorn
{
    class AcademyPopcornMain
    {
        const int WorldRows = 23;
        const int WorldCols = 40;
        const int RacketLength = 6;

        static void Initialize(Engine engine)
        {
            int startRow = 3;
            int startCol = 2;
            int endCol = WorldCols - 2;
            int wallStartRow = 0;
            
            // Initialize ceiling
            for (int i = wallStartRow; i < WorldCols; i++)
            {
                IndestructibleBlock ceiling = new IndestructibleBlock(new MatrixCoords(wallStartRow, i));
                engine.AddObject(ceiling);
            }

            // Initialize indestructible walls
            for (int i = wallStartRow + 1; i < WorldRows; i++)
            {
                IndestructibleBlock leftWallBlock = new IndestructibleBlock(new MatrixCoords(i,0));
                IndestructibleBlock rightWallBlock = new IndestructibleBlock(new MatrixCoords(i, WorldCols-1));
                engine.AddObject(leftWallBlock);
                engine.AddObject(rightWallBlock);
            }

            // Initialize exploding Blocks
            for (int i = startCol; i < endCol; i++)
            {
                if (i % 7 == 0)
                {
                    Block explBlock = new ExplodingBlock(new MatrixCoords(startRow+1, i));
                    engine.AddObject(explBlock);
                }
            }

            // Initialize Unpassable Blocks
            for (int i = startCol; i < endCol; i++)
            {
                if (i % 5 == 0)
                {
                    Block unpassableBlock = new UnpassableBlock(new MatrixCoords(WorldRows/2, i));
                    engine.AddObject(unpassableBlock);
                }
            }

            // Gift Blocks
            for (int i = startCol; i < endCol; i++)
            {
                if (i % 4 == 0)
                {
                    Block currBlock = new GiftBlock(new MatrixCoords(startRow - 1, i));
                    engine.AddObject(currBlock);
                }
            }

            // Original Blocks
            for (int i = startCol; i < endCol; i++)
            {
                Block currBlock = new Block(new MatrixCoords(startRow, i));
                engine.AddObject(currBlock);
            }

                // Original Ball

            //ball theball = new ball(new matrixcoords(worldrows / 2, 0),
            //new matrixcoords(-1, 1));

            //engine.addobject(theball);

                 // Meteorite Ball Test

            //Ball theBall = new MeteoriteBall(new MatrixCoords(WorldRows / 2, 0),
            //    new MatrixCoords(-1, 1));
            //engine.AddObject(theBall);


                // Unstoppable Ball Test

            UnstoppableBall theBall = new UnstoppableBall(new MatrixCoords(WorldRows / 2, 0),
                new MatrixCoords(-1, 1));
            engine.AddObject(theBall);

            Racket theRacket = new Racket(new MatrixCoords(WorldRows - 1, WorldCols / 2), RacketLength);
            engine.AddObject(theRacket);

                 // Add an instance and test the Trail Object
            //TrailObject trail = new TrailObject(new MatrixCoords(15, 20), new char[,] { { '%' } }, 10);

            //engine.AddObject(trail);
        }

        static void Main(string[] args)
        {
            IRenderer renderer = new ConsoleRenderer(WorldRows, WorldCols);
            IUserInterface keyboard = new KeyboardInterface();

            EngineShootingRacket gameEngine = new EngineShootingRacket(renderer, keyboard, 250);

            keyboard.OnLeftPressed += (sender, eventInfo) =>
            {
                gameEngine.MovePlayerRacketLeft();
            };

            keyboard.OnRightPressed += (sender, eventInfo) =>
            {
                gameEngine.MovePlayerRacketRight();
            };

            keyboard.OnActionPressed += (sender, eventInfo) =>
            {
                gameEngine.ShootPlayerRacket();
            };

            Initialize(gameEngine);

            //

            gameEngine.Run();
        }
    }
}
